package Game;

import java.util.ArrayList;
import java.util.Collections;

public class PokerGame01 {
    //牌盒
    //♥3 ♣3
    static ArrayList<String> list = new ArrayList<>();

    //静态代码块
    //特点：随着类的加载而在加载的，而且只执行一次。
    static {
        //准备牌
        // "♦", "♣", "♥", "♠"
        // "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K", "A", "2"
        String[] color = {"♦", "♣", "♥", "♠"};
        String[] number = {"3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K", "A", "2"};
        for (String c : color) {
            //c表示每一个牌的花色
            for (String n : number) {
                //n表示每一种牌号
                list.add(c + n);
            }
        }
        list.add("大王");
        list.add("小王");

    }

    public PokerGame01() {
        // 洗牌
        Collections.shuffle(list);
        // 发牌
        //定义4个集合，其中3个选手的牌,还要一个是用来存储地主多出来的3张牌
        ArrayList<String> dizhu = new ArrayList<>();
        ArrayList<String> player1 = new ArrayList<>();
        ArrayList<String> player2 = new ArrayList<>();
        ArrayList<String> player3 = new ArrayList<>();
        for (int i = 0; i < list.size(); i++) {
            //根据索引找到牌号，本质是要把前三张牌给地主
            String poke = list.get(i);//得到了第i张牌
            if (i <= 2) {
                dizhu.add(poke);//前三张给地主
                //依次轮流给3个选手发牌
            } else if (i % 3 == 0) {
                player1.add(poke);
            } else if (i % 3 == 1) {
                player2.add(poke);
            } else {
                player3.add(poke);
            }

        }
        //看牌
        lookpoke("张三",player1);
        lookpoke("李四",player2);
        lookpoke("王五",player3);

    }

    public void lookpoke(String name, ArrayList<String> list) {
        System.out.print(name + ": ");
        for (String poke : list) {
            //循环遍历得到每一张牌
            System.out.print(poke + " ");

        }
        System.out.println();
    }
}
